/**********************************************************
 *
 *  Copyright (c) 2003  SeikoEpson Inc
 *  All Rights Reserved
 *
 *  File name : f_acos.c
 *  Function  :
 *        f_asin function returns arccos's( cos^-1, not 1/cos) value.
 *        by given value.
 *        This file is copied from math.lib of 
 *                  CC33 tool(CC33v40.exe + CCPA45.exe, 
 *                  math of ansilib33v25 )
 *  original file's Revision  :
 *      2000/02/10    first release                 M.Igarashi
 *  Revision  :
 *      2003/ 3/14    IrumaSoft M.Takeishi   1.st design
 *
 **********************************************************/
#include	<f_math.h>
#include	<f_smcvals.h>

// ARGORITHM
// 1.
//        arccos x = pai/2 - asin(x)
//

//
//  the architecture of float floating point
//
//   0 30         23 22                0  32 bit
//   -----------------------------------
//  | |   exponent  |  fraction         |
//   -----------------------------------
//
//  |               |                   |
//  |    8 bits     |    23 bits        |
//
//         bit    31         sign bit        (  1 bit  )
//             30 - 23      exponent part    (  8 bits )
//             22 -  0      fraction part    ( 23 bits )
//
//
//


float f_acos (float sfX){

	long lX;
	unsigned long ulx;
	float sfRet;
	
	F_GETW(lX,sfX);		// get low
	
	ulx = lX&0x7fffffff;
	
	if(lX > 0x3f800000 ){	// check area
		errno = EDOM;
		sfRet = f_NAN._F;			// error
	}else{
		sfRet = F_HLFP - f_asin(sfX);	// calc acos()
	}
	
	return sfRet;
	
}
